home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / c / sas_c_emacs_b3.lha / sc_emacs.rexx < prev    next >
OS/2 REXX Batch file  |  1994-03-21  |  3KB  |  123 lines

  1. /*
  2.  *  FILE
  3.  *    sc_emacs.rexx
  4.  *
  5.  *  DESCRIPTION
  6.  *    Simple handler between GNUEmacs and SCMSG.
  7.  *
  8.  *    This program is used when SCMSG calls emacs. (When EMACS
  9.  *    asks SCMSG for information it can do it directly.)
  10.  *
  11.  *  AUTHOR
  12.  *    Anders Lindgren, d91ali@csd.uu.se
  13.  *
  14.  *  HISTORY
  15.  *    93-xxx-xx ALi *    Program written
  16.  *    94-Mar-21 ALi * zero2str removed as SCMSG now sends correct strings.
  17.  *              * The Emacs window is moved to the front.
  18.  *              * One extra 'a'x was added to the end of the GOTOFILE
  19.  *            line. Make sure that a corresponding options file
  20.  *            for SCMSG is used.
  21.  */
  22.  
  23. if ~Show('L','rexxsupport.library') then do
  24.         if ~AddLib('rexxsupport.library',0,-30,0) then do
  25.                 say 'Unable to open rexxsupport.library'
  26.                 exit 20
  27.         end
  28.     end
  29.  
  30. if ~Show('L','slashquote.library') then do
  31.         if ~AddLib('slashquote.library',0,-30,0) then do
  32.                 say 'Unable to open slashquote.library'
  33.                 exit 20
  34.         end
  35.     end
  36.  
  37.  
  38. port = 'SC_EMACS'
  39. if ~OpenPort(port) then do
  40.         say 'Error while opening port' port
  41.         exit 20
  42.     end
  43.  
  44. /* Start emacs if it's not already running */
  45. if show('p', 'EMACS1') = 0 then do
  46.     address command 'emacs'
  47.     delay(1100)
  48.     end
  49.  
  50. quit=0
  51.  
  52. do until quit
  53.         call WaitPkt(port)
  54.         pkt = GetPkt(port)
  55.         if pkt = Null() then do
  56.                 iterate
  57.         end
  58.  
  59.         msg = getarg(pkt, 0)
  60.  
  61.     /* The 'a'x:s are used as placeholders only */
  62.     parse VALUE msg WITH cmd line 'a'x errnum 'a'x,
  63.         class 'a'x file 'a'x text 'a'x
  64.  
  65.     retcode = 20
  66.  
  67.     select
  68.         when cmd = 'QUIT' then do
  69.             retcode = 0
  70.             quit = 1
  71.             end
  72.  
  73.         when cmd = 'GOTOLINE' then do
  74.             /* 
  75.              * This is a no-op, since everything is 
  76.              * baked into GOTOFILE 
  77.              */
  78.             retcode = 0
  79.             end
  80.  
  81.         when cmd = 'GOTOFILE' then do
  82.             
  83.             /*
  84.              * Undocumented feature: SCMSG quotes filenames
  85.              * and texts which contains spaces. VERY STUPID!
  86.              * How can a call be made to emacs without
  87.              * extensive parsing?
  88.              */
  89.  
  90.             if words(file) > 1 then do
  91.                 file=substr(file,2,length(file)-2)
  92.                 end
  93.             
  94.             if words(text) > 1 then do
  95.                 text=substr(text,2,length(text)-2)
  96.                 end
  97.  
  98.             /*
  99.              * Emacs can't handle quotes in strings as they are
  100.              * treated as the end of the string. 
  101.              * To overcome this all quotes and slashes are escaped 
  102.              * by a slash.
  103.              */
  104.             msg = '(sas-c-view-message ',
  105.                 slashquote(file) line slashquote(text),
  106.                     slashquote(class) errnum')'
  107.             /* call writeln(stderr, msg) */
  108.  
  109.             address 'EMACS1' '(amiga-window-to-front)'
  110.             address 'EMACS1' '(amiga-activate-window)'
  111.             address 'EMACS1' msg 
  112.             retcode = 0
  113.             end
  114.  
  115.         otherwise nop
  116.         end
  117.  
  118.     call Reply(pkt,retcode)
  119.             
  120.     end
  121.     
  122. ClosePort(port)
  123.